home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / ddj0897.zip / DYN401.ZIP / dpp / arglist.c next >
C/C++ Source or Header  |  1997-04-16  |  3KB  |  148 lines

  1.  
  2.  
  3. /*  Copyright (c) 1993-1996 Algorithms Corporation  */
  4. /*  All rights reserved.  */
  5.  
  6.  
  7.  
  8.  
  9. /*  This file automatically generated by dpp - do not edit  */
  10.  
  11. #define    DPP_STRATEGY    2
  12. #define    DPP_FASTWIDE    0
  13.  
  14.  
  15.  
  16. #line 17 "arglist.d"
  17. #include "dpp.h" 
  18.  
  19. #define    CLASS    ArgumentList_c
  20. #define    ivType    ArgumentList_iv_t
  21.  
  22. #include "generics.h"
  23.  
  24. object    ArgumentList_c;
  25.  
  26.  
  27. #line 21 "arglist.d"
  28. static void process_file(object, char *); 
  29.  
  30. cmeth objrtn ArgumentList_cm_gNew(object self)
  31.     return gShouldNotImplement(self, "gNew"); 
  32.  
  33. cmeth objrtn ArgumentList_cm_gNewArglist(object self, int argc, char **argv)
  34.     int i; 
  35.     object obj = oSuper(ArgumentList_c, gNew, self)(self); 
  36.     for (i=0 ; i < argc ; i++) 
  37.         if (argv[i][0] == '@') 
  38.         process_file(obj, 1+argv[i]); 
  39.     else 
  40.         gAddLast(obj, gNewWithStr(String, argv[i])); 
  41.     return obj; 
  42.  
  43. static void process_word(char *word, object list, int noexpand) 
  44.     int wild=0; 
  45.     char *w; 
  46.  
  47.     if (!noexpand) 
  48.         for (w=word ; *w ; w++) 
  49.         if (*w == '*' || *w == '?') { 
  50.         wild = 1; 
  51.         break; 
  52.     } 
  53.     if (!wild) { 
  54.         gAddLast(list, gNewWithStr(String, word)); 
  55.         return; 
  56.     } 
  57.  
  58.  
  59.  
  60.     gAddLast(list, gNewWithStr(String, word)); 
  61.  
  62.  
  63. #define space(x) ((x) <= ' ') 
  64.  
  65. static char *process_token(char *p, object list) 
  66.     char word[128], *w; 
  67.     int inquote, noexpand; 
  68.  
  69.     while (*p && space(*p)) 
  70.         p++; 
  71.     if (noexpand = inquote = *p == '"') 
  72.         p++; 
  73.     for (w=word ; *p && (!space(*p) || inquote) ; p++) 
  74.         if (inquote && *p == '"') 
  75.         inquote = 0; 
  76.     else 
  77.         *w++ = *p; 
  78.     *w = '\0'; 
  79.     if (*word == '@') 
  80.         process_file(list, word+1); 
  81.     else if (*word) 
  82.         process_word(word, list, noexpand); 
  83.     return p; 
  84.  
  85. static void process_file(object list, char *file) 
  86.     char buf[256], *p; 
  87.     object fobj; 
  88.  
  89.     fobj = gOpenFile(File, file, "r"); 
  90.     if (!fobj) { 
  91.         vPrintf(stdoutStream, "Can't open %s\n", file); 
  92.         exit(1); 
  93.     } 
  94.     while (gGets(fobj, buf, sizeof buf)) 
  95.         for (p=buf ; *(p=process_token(p, list)) ; ); 
  96.     gDispose(fobj); 
  97.  
  98. #line 109 "arglist.c"
  99.  
  100. objrtn    ArgumentList_initialize(void)
  101. {
  102.     static  CRITICALSECTION  cs;
  103.     static  int volatile once = 0;
  104.  
  105.     ENTERCRITICALSECTION(_CI_CS_);
  106.     if (!once) {
  107.         INITIALIZECRITICALSECTION(cs);
  108.         once = 1;
  109.     }
  110.     LEAVECRITICALSECTION(_CI_CS_);
  111.  
  112.     ENTERCRITICALSECTION(cs);
  113.  
  114.     if (ArgumentList_c) {
  115.         LEAVECRITICALSECTION(cs);
  116.         return ArgumentList_c;
  117.     }
  118.     INHIBIT_THREADER;
  119.     LinkObject_initialize();
  120.     if (ArgumentList_c)  {
  121.         ENABLE_THREADER;
  122.         LEAVECRITICALSECTION(cs);
  123.         return ArgumentList_c;
  124.     }
  125.     ArgumentList_c = gNewClass(Class, "ArgumentList", 0, 0, LinkObject, END);
  126.     cMethodFor(ArgumentList, gNew, ArgumentList_cm_gNew);
  127.     cMethodFor(ArgumentList, gNewArglist, ArgumentList_cm_gNewArglist);
  128.  
  129.     ENABLE_THREADER;
  130.  
  131.     LEAVECRITICALSECTION(cs);
  132.  
  133.     return ArgumentList_c;
  134. }
  135.  
  136.  
  137.  
  138.